// System Unit
// Windows API

(*************)
(* Interface *)
(*************)
{$IFDEF Include_Modules_Header}

 Function _WIN_LocalAlloc(Const Flags: Cardinal; Const Size: Integer): Pointer; StdCall;
 Function _WIN_LocalFree(Const Addr: Pointer): Pointer; StdCall;
 Function _WIN_TLSAlloc: Integer; StdCall;
 Function _WIN_TLSFree(Const TLSIndex: Integer): LongBool; StdCall;
 Function _WIN_TLSGetValue(Const TLSIndex: Integer): Pointer; StdCall;
 Function _WIN_TLSSetValue(Const TLSIndex: Integer; Const TLSValue: Pointer): LongBool; StdCall;

 Function _WIN_GetCurrentThreadID: Cardinal;
 Function _WIN_CreateThread(ThreadAttributes: Pointer; StackSize: Cardinal; StartAddress, Parameter: Pointer;
                            CreationFlags: Cardinal; Var ThreadID: Cardinal): Cardinal; StdCall;
 Procedure _WIN_ExitThread(dwExitCode: Cardinal); StdCall;
 Procedure _WIN_ExitProcess(ExitCode: Cardinal); StdCall;

 Procedure _WIN_RaiseException(Const ExceptionCode, ExceptionFlags, NumberOfArguments: Cardinal; Args: Pointer); StdCall;
 Function _WIN_RtlUnwind(ExcReg: PExceptionRegistry; TargetIP: Pointer; Var ExcRec: TExceptionRecord; ReturnValue: Pointer): Pointer; StdCall;
 Procedure _WIN_OutputDebugString(Const OutputString: PChar); StdCall;

 Procedure _WIN_MessageBox(hWnd: NativeUInt; Text, Caption: PChar; &Type: Cardinal); StdCall;
 Function _WIN_LoadString(hInstance: NativeUInt; uID: Cardinal; lpBuffer: PChar; nBufferMax: Integer): Integer; StdCall;
 Function _WIN_LStrLen(lpString: PChar): Integer; StdCall;

 Function _WIN_GetLastError: Cardinal; StdCall;
 Procedure _WIN_SetLastError(ErrorCode: Cardinal); StdCall;
 Function _WIN_SetErrorMode(uMode: Cardinal): Cardinal; StdCall;

 Function _WIN_GetModuleHandle(ModuleName: PWideChar): NativeUInt; StdCall;
 Function _WIN_GetModuleHandleEx(Flags: Cardinal; ModuleName: PChar; Var Module: NativeUInt): LongBool; StdCall;
 Function _WIN_LoadLibrary(lpLibFileName: PChar): NativeUInt; StdCall;
 Function _WIN_LoadLibraryEx(LibName: PChar; hFile: NativeUInt; Flags: Cardinal): NativeUInt; StdCall;
 Function _WIN_GetProcAddress(Module: NativeUInt; ProcName: PANSIChar): Pointer; StdCall;
 Function _WIN_FreeLibrary(ModuleHandle: NativeUInt): LongBool; StdCall;
 Procedure _WIN_FreeLibraryAndExitThread(ModuleHandle: NativeUInt; dwExitCode: Cardinal); StdCall;

{$ENDIF Include_Modules_Header}
(******************)
(* Implementation *)
(******************)
{$IFDEF Include_Modules_Implement}

 Const
  _Kernel_ = 'Kernel32.dll';
  _User_ = 'User32.dll';

 Function _WIN_LocalAlloc;  External _Kernel_ name 'LocalAlloc';
 Function _WIN_LocalFree;   External _Kernel_ name 'LocalFree';
 Function _WIN_TLSAlloc;    External _Kernel_ name 'TlsAlloc';
 Function _WIN_TLSFree;     External _Kernel_ name 'TlsFree';
 Function _WIN_TLSGetValue; External _Kernel_ name 'TlsGetValue';
 Function _WIN_TLSSetValue; External _Kernel_ name 'TlsSetValue';

 Function _WIN_GetCurrentThreadID; External _Kernel_ name 'GetCurrentThreadId';
 Function _WIN_CreateThread;       External _Kernel_ name 'CreateThread';
 Procedure _WIN_ExitThread;        External _Kernel_ name 'ExitThread';
 Procedure _WIN_ExitProcess;       External _Kernel_ name 'ExitProcess';

 Procedure _WIN_RaiseException;    External _Kernel_ name 'RaiseException';
 Function _WIN_RtlUnwind;          External _Kernel_ name 'RtlUnwind';
 Procedure _WIN_OutputDebugString; External _Kernel_ name 'OutputDebugStringW';

 Procedure _WIN_MessageBox;   External _User_ name 'MessageBoxW';
 Function _WIN_LoadString;    External _User_ name 'LoadStringW';
 Function _WIN_LStrLen;       External _Kernel_ name 'lstrlenW';

 Function _WIN_GetLastError;  External _Kernel_ name 'GetLastError';
 Procedure _WIN_SetLastError; External _Kernel_ name 'SetLastError';
 Function _WIN_SetErrorMode;  External _Kernel_ name 'SetErrorMode';

 Function _WIN_GetModuleHandle;           External _Kernel_ name 'GetModuleHandleW';
 Function _WIN_GetModuleHandleEx;         External _Kernel_ name 'GetModuleHandleExW';
 Function _WIN_LoadLibrary;               External _Kernel_ name 'LoadLibraryW';
 Function _WIN_LoadLibraryEx;             External _Kernel_ name 'LoadLibraryExW';
 Function _WIN_GetProcAddress;            External _Kernel_ name 'GetProcAddress';
 Function _WIN_FreeLibrary;               External _Kernel_ name 'FreeLibrary';
 Procedure _WIN_FreeLibraryAndExitThread; External _Kernel_ name 'FreeLibraryAndExitThread';

{$ENDIF Include_Modules_Implement}
(******************)
(* Initialization *)
(******************)
{$IFDEF Include_Modules_Initialize}
{$ENDIF Include_Modules_Initialize}
(****************)
(* Finalization *)
(****************)
{$IFDEF Include_Modules_Finalize}
{$ENDIF Include_Modules_Finalize}
